import pyaudio

def get_available_voice_devices():
    p = pyaudio.PyAudio()

    # 先列出所有可用的音频输入设备
    info = p.get_host_api_info_by_index(0)
    num_devices = info.get('deviceCount')
    input_device_index = None

    print("可用的音频输入设备：")
    for i in range(num_devices):
        device_info = p.get_device_info_by_host_api_device_index(0, i)
        if device_info.get('maxInputChannels') > 0:  # 只显示有输入通道的设备
            print(f"设备{i}: {device_info.get('name')}")


def show_device_parameters(input_device_index):
    p = pyaudio.PyAudio()
    if input_device_index is not None:
        device_info = p.get_device_info_by_host_api_device_index(0, input_device_index)
        device_rate = int(device_info.get('defaultSampleRate'))
        device_channels = device_info.get('maxInputChannels')
        print(f"使用设备: {device_info.get('name')}, 采样率: {device_rate}, 通道数: {device_channels}")

if __name__ == "__main__":
    # get_available_voice_devices()
    show_device_parameters(1)